//
//  UITableView+Adapter.m
//  UEPersonage
//
//  Created by mac on 2017/9/27.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UITableView+Adapter.h"
#import <objc/runtime.h>

@implementation UITableView (Adapter)


/**
替换初始化方法
 */
+(void)load{

    Method orginMethod = class_getInstanceMethod(self, @selector(initWithFrame:style:));
    Method adapter_Method = class_getInstanceMethod(self, @selector(adapter_initWithFrame:style:));
    method_exchangeImplementations(orginMethod, adapter_Method);
}

/**
 重写tableview初始化方法
 */
- (instancetype)adapter_initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    
    //适配iphoneX
    CGRect frame_new;
    if (iPhoneX){
        frame_new = CGRectMake(frame.origin.x, frame.origin.y+NAVIGATION_EXCURSION, frame.size.width, frame.size.height-NAVIGATION_EXCURSION);
    }
    else{
        frame_new = frame;
    }
    UITableView *tableview = [self adapter_initWithFrame:frame_new style:style];
    
    //适配iOS11
    if (@available(iOS 11.0, *)) {
        tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//        tableview.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
//        tableview.scrollIndicatorInsets = tableview.contentInset;
    }
    
    if (style == UITableViewStyleGrouped) {
        tableview.estimatedRowHeight = 0;
        tableview.estimatedSectionFooterHeight = 0;
        tableview.estimatedSectionHeaderHeight = 0;
    }
    return tableview;
}


@end
